﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using WINBASE.Utils;
using WINBASE.Utils.NETHelper;
using WINBASE.Utils.DTHelper;
using WINBASE.Controls;
using System.Reflection;

namespace WINBASE
{
    public partial class frmFmvm : WLCMainForm
    {
        #region Constructor & Load

        public frmFmvm()
        {
            InitializeComponent();
            if (LicenseManager.UsageMode != LicenseUsageMode.Runtime) return;
            InitializeUI();
        }

        #endregion

        #region Event

        private void frmFmvm_Leave(object sender, EventArgs e)
        {
            this.DataGrid.SaveColumnOrder();
        }

        void DataGrid_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.Enter | Keys.Return:
                    DataGrid_CellDoubleClick(null, null);
                    break;

                default: break;
            }
        }

        void DataGrid_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (this.DataGrid.SelectedRows.Count > 0)
            {
                DataRowView dr = (DataRowView)this.DataGrid.SelectedRows[0].DataBoundItem;
                ApplicationObject.FrmModuleList.ShowDetailForm(dr);
            }
        }

        #endregion

        #region Method

        public void InitializeUI()
        {
            this.DataGrid = new WINBASE.Controls.WLCDataGridView();
            this.DataGrid.CellDoubleClick += DataGrid_CellDoubleClick;
            this.DataGrid.KeyDown += DataGrid_KeyDown;
            WLCPnlGrid.Controls.Add(this.DataGrid);

            this.DataGridViewFilter = new Controls.WLCViewToolStrip(this.DataGrid);
            pnlViewFilter.Controls.Add(this.DataGridViewFilter);
        }

        public override void InitializeData()
        {
            if ((this.InvokeRequired))
            {
                this.Invoke((MethodInvoker)delegate
                {
                    InitializeData();
                    return;
                });
            }
            else
            {
                this.DataGrid.Name = "dgv" + this.ControlName.Right(5);
                this.DataGrid.ViewName = this.FormView;
                this.DataGrid.InitializeData();
                this.DataGridViewFilter.InitializeData();
                return;
            }
        }

        public override void InitializeData(DataTable Dt)
        {
            if ((this.InvokeRequired))
            {
                this.Invoke((MethodInvoker)delegate
                {
                    InitializeData(Dt);
                    return;
                });
            }
            else
            {
                this.DataGrid.Name = "dgv" + this.ControlName.Right(5);
                this.DataGrid.DataSource = Dt;
                this.DataGridViewFilter.InitializeData();
                return;
            }
        }

        #endregion
    }
}